<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: IconEnum.VIEW,
              tooltip: '查看',
              auth: CashAuth.SINGLE,
              onClick: handleView.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
  </div>
</template>

<script setup lang="ts">
  import { listCashApi } from '@/api/core/cash.api';
  import { IconEnum } from '@/enums/basic';
  import { BasicTable, TableAction, useTable } from '@/components/Table';
  import { CashAuth } from '@/auth/core/cash.auth';
  import { columns, searchFormSchema } from './cash.data';
  import { CashDetailGo } from '@/enums/core/cash.enum';
  import { useUserStore } from '@/store/modules/user';


  const [registerTable, { reload }] = useTable({
    title: '兑奖列表',
    api: listCashApi,
    striped: false,
    useSearchForm: true,
    rowKey: 'id',
    bordered: true,
    showIndexColumn: true,
    columns,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    showTableSetting: true,
    tableSetting: {
      fullScreen: true,
    },
    actionColumn: {
      width: 220,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
    },
  });

  /** 查看按钮 */
  function handleView(record: Recordable) {
    useUserStore().getRoutePath(CashDetailGo, record?.id);
  }
</script>
